package org.finjic.annotated.processor;

import org.finjic.annotated.processor.parser.ConfigFileParser;
import org.finjic.annotated.scanner.ComponentClassScanner;
import org.finjic.entity.BeanDefinition;

import java.util.Collections;
import java.util.Set;

/**
 * User: Taras
 * Date: 18.11.12
 * Time: 15:24
 */
public class AnnotationProcessor {
    private String configFileName;

    public AnnotationProcessor(String configFileName) {
        this.configFileName = configFileName;
    }

    public Set<BeanDefinition> processConfigFile(){
        String packageName = getBasePackageName();
        if(!isAnnotationBased(packageName)){
            return Collections.emptySet();
        }
        return new ComponentClassScanner(packageName).getComponentsFromPackage();
    }

    private boolean isAnnotationBased(String packageName){
        return packageName != null && !packageName.isEmpty();
    }

    private String getBasePackageName(){
        ConfigFileParser parser = new ConfigFileParser(configFileName);
        return parser.getPackageName();
    }
}
